package com.example.makerspace;


import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.example.makerspace.factory.testThreadPoolFactory;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.servlet.http.HttpServletResponse;

@RunWith(SpringRunner.class)
@SpringBootTest
public class test02 {
    public void main(String[] args) throws IOException, ParseException {

         time();
        //cacheThreadPoolTest();
    }

    /**
     * 可缓存无界线程池测试
     * 当线程池中的线程空闲时间超过60s则会自动回收该线程，核心线程数为0
     * 当任务超过线程池的线程数则创建新线程。线程池的大小上限为Integer.MAX_VALUE，
     * 可看做是无限大。
     */
    public void cacheThreadPoolTest() {
        // 创建可缓存的无界线程池，可以指定线程工厂，也可以不指定线程工厂
        ExecutorService executorService = Executors.newCachedThreadPool(new testThreadPoolFactory("cachedThread"));
        for (int i = 0; i < 10; i++) {
            executorService.submit(() -> {
                        System.out.println(Thread.currentThread().getName());
                    }
            );
        }
    }

    public  void  time() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd  HH:mm:ss");
        /**
         * 活动时间
         */
        String start_date="2024-6-7 12:0:0";
        String end_date="22024-6-8 12:0:0";
        LocalDate now = LocalDate.now();

        String localDateStr = now.format(fmt);


        Date date_start = sdf.parse(start_date);
        Date today = sdf.parse(localDateStr);
        Date date_end = sdf.parse(end_date);


        long startTimeMs = date_start.getTime();
        long endTimeMs = date_end.getTime();
        long time = today.getTime();

        if(time>=startTimeMs){
            System.out.println("小皮成功参与秒杀!");
        }else{
            System.out.println("小皮错过秒杀!");
        }
    }
}

